#ifndef CONN_HPP
#define CONN_HPP
#include <functional>
#include <sys/epoll.h>
#include "Addr.hpp"
#define LISTENSOCKFD 1
#define NORMALSOCKFD 2
class Connect;
class Reactor;
using handlers = std::function<void(Connect* conn)>;
class Connect
{
public:
    Connect(int sockfd, class Addr addr) : _sockfd(sockfd),
                                           _addr(addr)
    {
        _event.data.fd = _sockfd;
    }
    ~Connect() {}
    void LinkR(Reactor *R)
    {
        _R = R;
    }
    void RegistNormalHandlers(handlers Read,handlers Write,handlers Except)
    {
        _Read = Read;
        _Write = Write;
        _Except = Except;
    }
    void RegistListenHandlers(handlers Read,handlers Write,handlers Except)
    {
        _Read = Read;
        _Write = Write;
        _Except = Except;
    }
    struct epoll_event* Event()
    {
        return &_event;
    }
    int Sockfd()
    {
        return _sockfd;
    }

    int _type;
    class Addr _addr;
    handlers _Read;
    handlers _Write;
    handlers _Except;
    struct epoll_event _event;
    class Reactor *_R = nullptr;
    std::string _inbuffer;
    std::string _outbuffer;
private:
    int _sockfd;
};
#endif